#define  _CRT_SECURE_NO_WARNINGS
#include"string.h"
using namespace std;

namespace my_string
{
	void Test_String1()
	{
		string s1("Hello world");
		cout << s1.c_str() << endl;                              
		cout << s1.size() << endl;           
		cout << s1.capacity() << endl;

		string s2 = "Hello";
		cout << s2.c_str() << endl;
		cout << s2.size() << endl;
		cout << s2.capacity() << endl;

		string s3(s2);
		cout << s3.c_str() << endl;
		cout << s3.size() << endl;
		cout << s3.capacity() << endl;

		string s4 = s1;
		cout << s4.c_str() << endl;
		cout << s4.size() << endl;
		cout << s4.capacity() << endl;

		s4 = s2;
		cout << s4.c_str() << endl;
		cout << s4.size() << endl;
		cout << s4.capacity() << endl;
	}

	void Test_String2()
	{
		string s1 = "Hello World";
		string::iterator it = s1.begin();
		while (it != s1.end())
		{
			(*it)++;
			cout << *it << ' ';
			++it;
		}
		cout << endl;

		const string s2(s1);
		string::const_iterator cit = s2.begin();
		while (cit != s2.end())
		{
			cout << *cit << ' ';
			++cit;
		}
		cout << endl;

		for (char e : s2)
		{
			cout << e << ' ';
		}
	}

	void Test_String3()
	{
		string s1 = "Hello World";
		s1.reserve(100);
		cout << s1.c_str() << endl;
		cout << s1.size() << endl;
		cout << s1.capacity() << endl;

		cout << s1[0] << endl;
		++s1[0];
		cout << s1.c_str() << endl;

		string s2 = "Hello";
		s2.resize(2);
		cout << s2.c_str() << endl;
		cout << s2.size() << endl;
		cout << s2.capacity() << endl;

		s2.resize(4);
		cout << s2.c_str() << endl;
		cout << s2.size() << endl;
		cout << s2.capacity() << endl;

		s2.resize(10);
		cout << s2.c_str() << endl;
		cout << s2.size() << endl;
		cout << s2.capacity() << endl;

		//std::string s2 = "Hello";
		//s2.resize(2);
		//cout << s2.c_str() << endl;
		//cout << s2.size() << endl;
		//cout << s2.capacity() << endl;

		//s2.resize(4);
		//cout << s2.c_str() << endl;
		//cout << s2.size() << endl;
		//cout << s2.capacity() << endl;

		//s2.resize(10);
		//cout << s2.c_str() << endl;
		//cout << s2.size() << endl;
		//cout << s2.capacity() << endl;

	}

	void Test_String4()
	{
		string s1 = "Hello World";
		string s2 = "Hello";
		cout << (s1 < s2) << endl;
		cout << (s2 < s1) << endl;

		string s3(s1);
		cout << (s1 == s3) << endl;
		cout << (s2 == s3) << endl;
		cout << (s1 >= s2) << endl;
		cout << (s1 != s2) << endl;
		cout << (s2 <= s1) << endl;

	}

	void Test_String5()
	{
		string s1("Hello");
		s1.push_back('x');
		s1 += 'x';
		s1 += "xxxxx";
		cout << s1.c_str() << endl;
		cout << s1.size() << endl;
		cout << s1.capacity() << endl;

		const char* p = "Worldxxxxxxx";
		string s3 = "Hello ";
		cout << s3.c_str() << endl;
		cout << s3.size() << endl;
		cout << s3.capacity() << endl;
		s3.append(p);
		cout << s3.c_str() << endl;
		cout << s3.size() << endl;
		cout << s3.capacity() << endl;

		string s4 = "Hello";
		string s5 = "Worldxxxxxxxx";
		cout << s4.c_str() << endl;
		cout << s4.size() << endl;
		cout << s4.capacity() << endl;
		cout << s5.c_str() << endl;
		cout << s5.size() << endl;
		cout << s5.capacity() << endl;
		s4.swap(s5);
		cout << s4.c_str() << endl;
		cout << s4.size() << endl;
		cout << s4.capacity() << endl;
		cout << s5.c_str() << endl;
		cout << s5.size() << endl;
		cout << s5.capacity() << endl;
	}

	void Test_String6()
	{
		string s1 = "Hello ";
		cout << s1.find('e') << endl;
		s1 += "World";
		cout << s1.find("Wor") << endl;
		cout << s1.c_str() << endl;
		cout << s1.size() << endl;
		cout << s1.capacity() << endl;
		// "Hello World"
		s1.insert(0, 'x');
		cout << s1.c_str() << endl;
		cout << s1.size() << endl;
		cout << s1.capacity() << endl;

		string s2 = "Hello World";
		//s2.erase(1, 2);
		s2.insert(11, "xxx");
		cout << s2.c_str() << endl;
		cout << s2.size() << endl;
		cout << s2.capacity() << endl;
	}

	void Test_String7()
	{
		string s1 = "Hello World";
		cout << s1 << endl;
		cin >> s1;
		cout << s1 << endl;
	}

}

int main()
{
	my_string::Test_String2();
	return 0;
}